<template>
  <div class="app-container">\
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
      class="el-forms"
    >
      <div class="handle_box_content" ref="handle_box_content">
        <el-form-item label="查评事件" prop="FACTORY">
          <el-select
            v-model="queryParams.reviewEvents"
            clearable
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="(item, index) in EventsOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评审状态" prop="custodyPerson">
          <el-select
            v-model="queryParams.reviewStatus"
            clearable
            @keyup.enter.native="handleQuery"
          >
            <el-option
              v-for="(item, index) in StatusOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
<!--        <el-button-->
<!--          plain-->
<!--          size="mini"-->
<!--          :icon="Showbox ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"-->
<!--          @click="handleShow"-->
<!--          >{{ Showbox ? "隐藏" : "展开" }}</el-button-->
<!--        >-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:manger:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:manger:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:manger:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:manger:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="mangerList"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      ref="table"
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="查评要素" align="center" prop="evaluationElements" />
      <el-table-column label="查评事件" width="250" align="center" prop="reviewEvents" />
      <el-table-column label="小组名称" width="200" align="center" prop="groupName" />
      <el-table-column label="组长" width="90" align="center" prop="groupLeader" />
      <el-table-column label="成员" width="200" align="center" prop="member" />
      <el-table-column label="评审状态" width="80" align="center" prop="reviewStatus" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="creationDate"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creationDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        label="操作"-->
<!--        align="center"-->
<!--        width="150"-->
<!--        class-name="small-padding fixed-width"-->
<!--      >-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:manger:edit']"-->
<!--            >修改</el-button-->
<!--          >-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:manger:remove']"-->
<!--            >删除</el-button-->
<!--          >-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listManger,
  getManger,
  delManger,
  addManger,
  updateManger,
} from "@/api/system/manger";
import {listGroping,getGroping,addGroping,updateGroping,delGroping} from "../../../api/system/review/groping.js";
import PeopleSelect from "../../../components/Selection/index.vue"
import DepartmentDialog from "../../../components/DepartmentDialog/index.vue"
import {listEvent} from "@/api/system/review/event";
export default {
  name: "Manger",
  dicts: ["sys_normal_disable"],
  components: {
    PeopleSelect,
    DepartmentDialog
  },
  data() {
    return {
      // 按钮loading
      // buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工器具管理表格数据
      mangerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        reviewEvents: undefined,   //查评事件
        groupName: undefined,   //小组名称
        groupLeader: undefined,    //小组组长
        groupLeaderCode: undefined,   //组长编号
        member: undefined,    //成员
        memberCode: undefined,   //成员编号
        creationDate: undefined,   //创建时间
        isDelete: undefined,    //是否删除
        taskAllocation: undefined,    //任务分配
        reviewStatus: undefined,  //评审状态
        evaluationElements: undefined,  //查评要素
        standardScore: undefined   //标准分
      },
      // 表单参数
      form: {},
      StatusOptions: [
        {
          label: "已评审",
          value: "已评审",
        }, {
          label: "未评审",
          value: "未评审",
        },
      ],
      EventsOptions: [{
      }],
      Showbox:false,
      peopleOpen:false,
      peopleOpen1:false,
      // 表单校验
      rules: {
        ID: [{ required: true, message: "主键id不能为空", trigger: "blur" }],
        REMARK: [{ required: true, message: "备注不能为空", trigger: "blur" }],
        FILE: [
          { required: true, message: "附件信息不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.querListEvent();
  },
  methods: {
    open1() {
      this.peopleOpen = true;
    },
    open2() {
      this.peopleOpen1 = true;
    },
    //选择人的确定按钮事件 submitPeople(nikeNamelist)方法传参一个默认接收用户昵称数组   submitPeople(peopleList,nikeNamelist)方法传参两个则是接收用户昵称数组和用户账号数组
    submitPeople(peopleList) {
      //console.log(peopleList);
      this.peopleOpen = false;
    },
    submitPeople1(peopleList) {
      //console.log(peopleList);
      this.peopleOpen1 = false;
    },
     handleRowClick(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    handleShow() {
      this.Showbox = !this.Showbox
      const element = this.$refs.handle_box_content;
      if(this.Showbox){
        element.style.overflow = 'visible';
        element.style.height = 'fit-content'
      }else {
        element.style.overflow = 'hidden';
        element.style.height = '50px'
      }
    },
    /** 查询工器具管理列表 */
    getList() {
      this.loading = true;
      //console.log(this.queryParams)
      listGroping(this.queryParams).then((response) => {
        this.mangerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        reviewEvents: undefined,   //查评事件
        groupName: undefined,   //小组名称
        groupLeader: undefined,    //小组组长
        groupLeaderCode: undefined,   //组长编号
        member: undefined,    //成员
        memberCode: undefined,   //成员编号
        creationDate: undefined,   //创建时间
        isDelete: undefined,    //是否删除
        taskAllocation: undefined,    //任务分配
        reviewStatus: undefined,  //评审状态
        evaluationElements: undefined,  //查评要素
        standardScore: undefined   //标准分
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查询查评事件 */
    querListEvent(){
      listEvent().then((response) => {
        this.EventsOptions = [];
        response.rows.forEach((item) =>{
          this.EventsOptions.push({
            "label": item.eventTitle,
            "value": item.eventTitle
          })
        })
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/review/reviewPrepare/evaluationGroupingForm",
        query: {title:"查评分组表单" },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.loading = true;
      this.reset();
      const ID = row.id || this.ids;
      getManger(ID).then((response) => {
        // this.loading = false;
        // this.form = response.data;
        // this.open = true;
        // this.title = "修改工器具管理";
      });

      this.$router.push({
        path: "/review/reviewPrepare/evaluationGroupingForm",
        query: { ID:ID,title:"修改工器具管理",flowId:1 },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // this.buttonLoading = true;
          if (this.form.ID != null) {
            updateManger(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                // this.buttonLoading = false;
              });
          } else {
            addManger(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                // this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除工器具管理编号为"' + IDs + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delGroping(IDs);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/manger/export",
        {
          ...this.queryParams,
        },
        `manger_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.handle_box_content {
  width: 81%;
  height: 50px;
  overflow: hidden;
}
.el-forms{
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
}
</style>
